//搜索栏提示
var searchTxt = $('#mainNav .searchField .txt');
searchTxt.focus(function(){
	if($(this).val()=='驾车宝典'){
		$(this).val('').css('color','#333');
	}
});
searchTxt.blur(function(){
	if($(this).val()==''){
		$(this).val('驾车宝典').css('color','#9f9f9f');
	}
});


function setBorder(elementId){
	 $('#'+elementId).css("border-color","red");
	 $('#'+elementId).css("border-style","solid");
}
function clearBorder(elementId){
	 $('#'+elementId).css("border-color","black");
	  $('#'+elementId).css("border-style","solid");
}

$(function(){

//活动内容页点击我要报名
var signUpBtn = $('.signUpPanel_01 .btnField .btn');
var signUpField = $('#jumpBox');
var signUpClose = $('#jumpBox .close');

signUpBtn.click(function(){
	signUpField.fadeIn(300);
});

signUpClose.click(function(){
	signUpField.fadeOut(300);
});
//活动内容页报名用户展开
var showMemberBtn = $('.forumContentPanel_01 .memberField .btns .btn1');
var showMemberField = $('.forumContentPanel_01 .memberField .list ul');
var showMemberHeight0 = showMemberField.height();
showMemberField.css('height','auto');
var showMemberHeight1 = showMemberField.height();
showMemberField.css('height',showMemberHeight0);
var showMemberOpen = false;
showMemberBtn.click(function(){
	if(showMemberOpen){
		showMemberField.stop().animate({height:showMemberHeight0},300);
		showMemberBtn.removeClass('on');
		showMemberOpen = false;
	}else{
		showMemberField.stop().animate({height:showMemberHeight1},300);
		showMemberBtn.addClass('on');
		showMemberOpen = true;
	}
});
});


//让左右两边对齐的JS 如对齐方式有误 请注释掉以下整段文档 或在无需自动对齐的页面最末写上以下代码<script>autoEqHeight = false;</script>
var leftLastItem = $('#leftArea').children().last();
var rightLastItem = $('#rightArea').children().last();
var autoEqHeight = true;

function eqHeight(){
	if(leftLastItem.length&&rightLastItem.length){
		if(leftLastItem.offset().top+leftLastItem[0].offsetHeight<rightLastItem.offset().top+rightLastItem[0].offsetHeight){
			leftLastItem.css('height',leftLastItem.height()+rightLastItem.offset().top+rightLastItem[0].offsetHeight -leftLastItem.offset().top-leftLastItem[0].offsetHeight );
		}else{
			rightLastItem.css('height',rightLastItem.height()+leftLastItem.offset().top+leftLastItem[0].offsetHeight -rightLastItem.offset().top-rightLastItem[0].offsetHeight );
		}
	}
}
var eqHeightTimeout = setTimeout(function(){
	if(autoEqHeight){
		eqHeight();
	}
},100);









/**
 * 
 * @param {Object} inputId     校验的输入框的Id  若不满足条件则将文本框背景色变红
 * @param {Object} maxLength   最大长度
 * @param {Object} valueType   类型  string   number 
 * @param {Object} allowBank   是否允许空
 * @param {Object} lengthEquals 长度是否必须相等
 */
function checkInputValue(inputId,maxLength,valueType,allowBlank,lengthEquals){
	var value =  $('#'+inputId).val();
	if (typeof(value) == 'undefined'){
		alert("有未知的文本框id ="+inputId+",请联系管理员");
		return false;
	}
	// 判断是否为空
	if (allowBlank && value ==""){
		return true;
	}else{//允许为空 
		if (value.length == 0 ){
		 	alert("输入项不允许为空,请查看页面上标红的文本框");
		    $('#'+inputId).css("background-color","red");
			$('#'+inputId).focus();
			return  false;
		}  
	}
	// 判断是 字符串 还是数字
	if (valueType == 'string') {
		 //判断是否超长
		if (value.length > maxLength) {
			alert("输入项过长,该项的最大长度为  " + maxLength + ",目前输入的长度为  "+value.length+" ,请查看页面上标红的文本框");
			  $('#'+inputId).css("background-color","red");
			  $('#'+inputId).focus();
			return false;
		}
	}
	if(valueType == 'number'){
		// 如果是数字的话 maxLength就转变为校验数字的位数  例如手机号码必须为 11位数字 
		// maxLength  = 0 则表示不限制位数
		if (lengthEquals) {
			if (value.length != maxLength) {
				alert("输入项长度不正确,该项的长度为  " + maxLength + ",目前输入的长度为  " + value.length + " ,请查看页面上标红的文本框");
				$('#' + inputId).css("background-color", "red");
				$('#' + inputId).focus();
				return false;
			}
		}else{
			//判断是否超长
			if (value.length > maxLength) {
				alert("输入项过长,该项的最大长度为  " + maxLength + ",目前输入的长度为  "+value.length+" ,请查看页面上标红的文本框");
				  $('#'+inputId).css("background-color","red");
				  $('#'+inputId).focus();
				return false;
			}
		}
		if ( isNumber(value)){
			
		}else{
			alert("输入项必须为数字,请查看页面上标红的文本框");
			$('#'+inputId).css("background-color","red");
			$('#'+inputId).focus();
			return false;
		}
	}
	$('#'+inputId).css("background-color","");
	return true;
}

//获取单选按钮被选中值
function getCheckedValue(radioName){
	var radio = document.getElementsByName(radioName);
	for(var i = 0;i < radio.length;i++){
	    if(radio[i].checked){
	    	return radio[i].value;
	    }
  	}
}

/**
 *验证是否数字(param  len < 0 则验证是否数字，len > 0 则还验证长度) 
 * @param {Object} value
 */
function isNumber(value){
	var strP = /^\d+(\.\d+)?$/; //验证是否数字
	if(!strP.test(value))return false;
	return true;
}

//活动内容页点击我要报名 以及所有页面的弹出登录框　　
var jumpBoxBtn1 = $('#topNav .linkField .links a:eq(1)'); //重要！！！！！！！！！！！！！此处请修改为打开快捷登录框对应的按钮或删除！！！！
var jumpBoxBtn2 = $('.signUpPanel_01 .btnField .btn');
var jumpBoxContent = [$('#jumpBox .loginPanel_01'),$('#jumpBox .signUpPanel_02')];
var btnClose =$('#jumpBox .close');
var jumpBox = $('#jumpBox');

function showJumpBox(num) {
	num = num || 0;
	if(jumpBoxContent[num].length>0){
		for(var i in jumpBoxContent){
			if(parseInt(i)==num){
				jumpBoxContent[i].fadeIn(300);
			}else{
				jumpBoxContent[i].hide();
			}
		}
		if (jumpBox.css('display') == 'none') {
			jumpBox.fadeIn(300, function () {
				btnClose.unbind().bind('click', function () {
					jumpBox.fadeOut(300);
				});
			});
		}
	}
}

jumpBoxBtn1.click(function(){
	showJumpBox(0);
});

jumpBoxBtn2.click(function(){
	showJumpBox(1);
});


//登录注册页输入框提示
$('.loginNRegPanel_01 .list li').each(function(){
	var $this = $(this);
	if($this.find('.txt').length){
		$this.attr('jqInfoShow','true');
		if($this.find('.txt').val().length>0){
			$this.attr('jqInfoShow','false');
			$this.css('background-position','0 100%');
		}
		$this.find('input').focus(function(){
			if($this.attr('jqInfoShow')=='false'&&$(this).val().length>0){
				$(this).select();
			}else{
				$this.attr('jqInfoShow','false');
				$this.css('background-position','0 100%');
			}
		}).blur(function(){
			if(!$(this).val().length){
				$this.attr('jqInfoShow','true');
				$this.css('background-position','0 0');
			}
		});
	}
});

$('.loginPanel_01 .formField li').each(function(){
	var $this = $(this);
	if($this.find('.txt').length){
		$this.attr('jqInfoShow','true');
		if($this.find('.txt').val().length>0){
			$this.attr('jqInfoShow','false');
			$this.css('background-position','-1px -36px');
		}
		$this.find('input').focus(function(){
			if($this.attr('jqInfoShow')=='false'&&$(this).val().length>0){
				$(this).select();
			}else{
				$this.attr('jqInfoShow','false');
				$this.css('background-position','-1px -36px');
			}
		}).blur(function(){
			if(!$(this).val().length){
				$this.attr('jqInfoShow','true');
				$this.css('background-position','-1px -1px');
			}
		});
	}
});


//注册页密码强度
var passwordEnterInput = $('.loginNRegPanel_01 .list .pw .txt');
var passwordStrength = $('.loginNRegPanel_01 .list .pwStrength');
var passwordStrengthLength = [1,10,15];

passwordEnterInput.keyup(function(e){
	var tempStrength = -1;
	for(var i in passwordStrengthLength){
		if($(this).val().length >= passwordStrengthLength[i] ){
			tempStrength = parseInt(i);
		}
	}
	passwordStrength.each(function(j){
		this.className = this.className.replace('On','');
		if(j == tempStrength ){
			this.className += 'On';
		}
	});
});



//找回密码输入框提示
var forgetPWTxt = $('.forgetPWPanel_01 .formField .list .txt');
forgetPWTxt.focus(function(){
	if($(this).val().length>0&&$(this).val()!='请输入你的注册邮箱或手机号'){
		$(this).select();
	}else if($(this).val()=='请输入你的注册邮箱或手机号'){
		$(this).val('').css('color','#333');
	}
});
forgetPWTxt.blur(function(){
	if($(this).val()==''){
		$(this).val('请输入你的注册邮箱或手机号').css('color','#999');
	}
});

